#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a=0;
	int b=1;
	int ans1=n,ans2=n;
	while(1){
		int c=a+b;
		a=b;
		b=c;
		if(n>c){
			ans1=c;
		}
		if(ans2<c){
			ans2=c;
			break;
		}
	}
//	cout<<"ans1=="<<ans1<<endl;
//	cout<<"ans2=="<<ans2<<endl;
    int ans=min(n-ans1,ans2-n);
	cout<<ans<<endl;
	return 0;
}
